﻿var selectLoad = function (id, url, value, callBack) {
    $.getJSON(appRoot + url, function (data, textStatus) {
        $("#" + id).empty();
        $.each(data, function (i, itemvalue) {
            $("#" + id).append($("<option></option>").val(itemvalue.Value).html(itemvalue.Text));
        });
        if (value != null)
            $("#" + id).val(value);
        if (callBack != null)
            callBack();
    });
};

var selectChangeLoad = function (id, parentId, url, value) {
    $("#" + parentId).change(function () {
        $.getJSON(appRoot + url + $("#" + parentId).val(), function (data, textStatus) {
            $("#" + id).empty();
            $.each(data, function (i, itemvalue) {
                $("#" + id).append($("<option></option>").val(itemvalue.Value).html(itemvalue.Text));
            });
            if (value != null)
                $("#" + id).val(value);
        });
    });
};

var allCheckEvent = function (id, subName) {
    $("#" + id).click(
        function () {
            if (this.checked) {
                $("input[name='" + subName + "']").each(function () { this.checked = true; });
            } else {
                $("input[name='" + subName + "']").each(function () { this.checked = false; });
            }
        });
};

var getCheckStr = function (subName, splitStr) {
    var re = "";
    $("input[name='" + subName + "']").each(function () { if (this.checked) { re += this.value + splitStr; } });
    return re;
};

var bindTextAreaEditor = function (id, random) {
    var upload = appRoot + 'Aspx/upload.aspx?rd=' + random;
    $('#' + id).xheditor({ tools: 'Cut,Copy,Paste,Pastetext,|,Blocktag,Fontface,FontSize,Bold, Italic,Underline,Strikethrough,FontColor,BackColor,SelectAll,Removeformat,|,Align,List,Outdent,Indent,|,Link,Unlink,Img,Flash,Media,Hr,Table,|,Source,Preview,Fullscreen', skin: 'o2007blue', upLinkUrl: upload, upImgUrl: upload, upFlashUrl: upload, upMediaUrl: upload });
};

var bindTextOnlyAreaEditor = function (id) {
    $('#' + id).xheditor({ tools: 'FontSize,Bold,Italic,Underline,Strikethrough,|,Align,List,|,Link,Img,Source' });
};

var rdTime = function () {
    return new Date().getTime();
};

